<?

		if($_REQUEST['act'] == "edit" && $_REQUEST['cmd'] == "true")
		{
			$valuearray['pd_code'] = $_POST['pd_code'];
			$valuearray['pd_name'] = $_POST['pd_name'];
			$valuearray['pd_name2'] = $_POST['pd_name2'];
			$valuearray['pd_dese'] = $_POST['description'];
			$valuearray['pd_dese2'] = $_POST['description2'];
			$valuearray['pd_price'] = $_POST['pd_price'];
			$valuearray['pd_price2'] = $_POST['pd_price2'];
			$valuearray['pd_unit'] = $_POST['pd_unit'];
			$valuearray['pd_unit2'] = $_POST['pd_unit2'];
			$valuearray['pd_promo'] = $_POST['pd_promo'];
			$valuearray['pd_promodes'] = $_POST['pd_promodes'];
			$valuearray['pd_promodes2'] = $_POST['pd_promodes2'];
			$valuearray['pd_shotdes'] = $_POST['pd_shotdes'];
			$valuearray['pd_shotdes2'] = $_POST['pd_shotdes2'];
			$valuearray['pd_publish'] = $_POST['pd_publish'];
			
			$valuearray['pd_size'] = $_POST['pd_size'];
			$valuearray['pd_size2'] = $_POST['pd_size2'];
			$valuearray['pd_color'] = $_POST['pd_color'];
			$valuearray['pd_nw'] = $_POST['pd_nw'];
			$valuearray['pd_nw2'] = $_POST['pd_nw2'];
			$valuearray['pd_ctnsize'] = $_POST['pd_ctnsize'];
			$valuearray['pd_ctnsize2'] = $_POST['pd_ctnsize2'];
			$valuearray['pd_gw'] = $_POST['pd_gw'];
			$valuearray['pd_gw2'] = $_POST['pd_gw2'];
			
			Qupdate("product",'',$valuearray," pd_id=".$_POST['pd_id'] );
			exit("<script type=\"text/javascript\">window.location='?body=product&step=1&c_id=".$_REQUEST['c_id']."&c_parent=".$_REQUEST['c_parent']."&act=edit&pd_id=".$_REQUEST['pd_id']."';</script>");
		}
		else if($_REQUEST['act'] == "add" && $_REQUEST['cmd'] == "true")
		{
			
			$maxorder = Q1("select MAX(pd_order) from product  ");
			$valuearray['pd_code'] = $_POST['pd_code'];
			$valuearray['pd_name'] = $_POST['pd_name'];
			$valuearray['pd_name2'] = $_POST['pd_name2'];
			$valuearray['pd_dese'] = $_POST['description'];
			$valuearray['pd_dese2'] = $_POST['description2'];
			$valuearray['pd_price'] = $_POST['pd_price'];
			$valuearray['pd_price2'] = $_POST['pd_price2'];
			$valuearray['pd_unit'] = $_POST['pd_unit'];
			$valuearray['pd_unit2'] = $_POST['pd_unit2'];
			$valuearray['pd_promo'] = $_POST['pd_promo'];
			$valuearray['pd_promodes'] = $_POST['pd_promodes'];
			$valuearray['pd_promodes2'] = $_POST['pd_promodes2'];
			$valuearray['pd_shotdes'] = $_POST['pd_shotdes'];
			$valuearray['pd_shotdes2'] = $_POST['pd_shotdes2'];
			$valuearray['pd_publish'] = $_POST['pd_publish'];
			
			$valuearray['pd_size'] = $_POST['pd_size'];
			$valuearray['pd_size2'] = $_POST['pd_size2'];
			$valuearray['pd_color'] = $_POST['pd_color'];
			$valuearray['pd_nw'] = $_POST['pd_nw'];
			$valuearray['pd_nw2'] = $_POST['pd_nw2'];
			$valuearray['pd_ctnsize'] = $_POST['pd_ctnsize'];
			$valuearray['pd_ctnsize2'] = $_POST['pd_ctnsize2'];
			$valuearray['pd_gw'] = $_POST['pd_gw'];
			$valuearray['pd_gw2'] = $_POST['pd_gw2'];
			
			if($_POST['pdzize']) foreach($_POST['pdzize'] as $a) $valuearray['pd_size'] .= $a."|";
			$valuearray['pd_order'] = $maxorder[0]+1;
			$valuearray['pd_ip'] = $_SERVER['REMOTE_ADDR'];
			$valuearray['c_id'] = $_REQUEST['c_parent'];			
			Qinsert("product","",$valuearray);
		}
		else if($_REQUEST['swap1'] >= 1 && $_REQUEST['swap2'] >= 1)
		{
				$r1 = Q1("select pd_id,pd_order from product  where pd_id =   ".$_REQUEST['swap1']);
				$r2 = Q1("select pd_id,pd_order from product  where pd_id =   ".$_REQUEST['swap2']);
				mysql_query("update product set pd_order = '".$r2['pd_order']."' where pd_id = '".$r1['pd_id']."'  ");
				mysql_query("update product set pd_order = '".$r1['pd_order']."' where pd_id = '".$r2['pd_id']."'  ");
		}
		else if($_REQUEST['delid'] >= 1)
		{
			mysql_query("DELETE FROM `product` WHERE `product`.`pd_id` = '".$_REQUEST['delid']."' LIMIT 1");

			$del1 = Q2("select img_pic from images where na_id = '".$_REQUEST['delid']."' and tables='product' ");
			foreach($del1 as $del)
			{
				@unlink("../imgs/".$del['img_pic']);
				@unlink("../imgs/".str_replace(".","-swap.",$del['img_pic']));
				@unlink("../imgs/".str_replace(".","-tmp.",$del['img_pic']));
			}
			mysql_query("DELETE FROM `images` WHERE `images`.`na_id` = ".$_REQUEST['delid']."  ");			
		}
		
		if($_REQUEST['c_parent'] == ""){$where = " c_status = 0 ";}
		else{$where = " c_parent = '".$_REQUEST['c_parent']."'  ";}
        $chk = Q2("select * from category where    ".$where."  ");
		//print_r($chk);
		//echo $_REQUEST['c_id'];
        if(count($chk) < 1)
		{
?>


<script type="text/javascript" src="js/ckeditor/ckeditor.js"></script>
<?
$r = Q1("select * from product where pd_id = '".$_REQUEST['pd_id']."' ");
$rx = Q1("select * from language limit 1");
?>			
            <fieldset>
            <legend>Step 2 : products box</legend>
            <form action="" method="post" name="a">
            <label>product code : </label><input name="pd_code" type="text" value="<?=$r['pd_code']?>" />
            <label>product name : </label> <?=$rx[lang1]?> <input name="pd_name" type="text" value="<?=$r['pd_name']?>" /> <?=$rx[lang2]?> <input name="pd_name2" type="text" value="<?=$r['pd_name2']?>" />

			<label>product size : </label> <?=$rx[lang1]?>  <input name="pd_size" type="text" value="<?=$r['pd_size']?>" />
			<?=$rx[lang2]?>  <input name="pd_size2" type="text" value="<?=$r['pd_size2']?>" />
            
            <label>product Ctn size : </label> <?=$rx[lang1]?>  <input name="pd_ctnsize" type="text" value="<?=$r['pd_ctnsize']?>" />
			<?=$rx[lang2]?>  <input name="pd_ctnsize2" type="text" value="<?=$r['pd_ctnsize2']?>" />
            
            <label>product N.W. : </label> <?=$rx[lang1]?>  <input name="pd_nw" type="text" value="<?=$r['pd_nw']?>" />
			<?=$rx[lang2]?>  <input name="pd_nw2" type="text" value="<?=$r['pd_nw2']?>" />
            
            <label>product G.W. : </label> <?=$rx[lang1]?>  <input name="pd_gw" type="text" value="<?=$r['pd_gw']?>" />
			<?=$rx[lang2]?>  <input name="pd_gw2" type="text" value="<?=$r['pd_gw2']?>" />
            
            <label>product color : </label><input name="pd_color" type="text" value="<?=$r['pd_color']?>" />
            
            <label>product price : </label> <?=$rx[lang1]?>  <input name="pd_price" type="text" value="<?=$r['pd_price']?>" />
			<?=$rx[lang2]?>  <input name="pd_price2" type="text" value="<?=$r['pd_price2']?>" />

			<label>unit price : </label> <?=$rx[lang1]?>  <input name="pd_unit" type="text" value="<?=$r['pd_unit']?>" />
			<?=$rx[lang2]?>  <input name="pd_unit2" type="text" value="<?=$r['pd_unit2']?>" />
            
            <label>shot description : </label> <?=$rx[lang1]?>  <input name="pd_shotdes" type="text" value="<?=$r['pd_shotdes']?>" />
			<?=$rx[lang2]?>  <input name="pd_shotdes2" type="text" value="<?=$r['pd_shotdes2']?>" />
			<br/><br/>
            <?
            	if($r['pd_promo'] == 1){
					 $checked = "checked";$display="block";
				}else{
					 $display="none";
				}
			?>
            <fieldset>
            	<legend>Promotion</legend>
                <input  type="checkbox" name = "pd_promo1" <?=$checked?> >Promotion</input><br/>
                 <div id = "promo_panel" style="display:<?=$display?>">
                    English : <br/><textarea name = "pd_promodes"><?=$r['pd_promodes']?></textarea><br/>
                    ไทย : <br/><textarea name = "pd_promodes2"><?=$r['pd_promodes2']?></textarea>
                 </div>
            </fieldset>
            <br/><br/>
            <?
            	if($r['pd_publish'] == 1){
					 $checked = "checked";$display="block";
				}else{
					 $display="none";$checked = "";
				}
			?>
            <input  type="checkbox" name = "pd_publish" <?=$checked?> >Publish on homepage.</input><br/>

           <!-- <label>product size : </label>
			<? $isize1 = array("UK 4", 'UK 6', 'UK 6-8', 'UK 8', 'UK 8-10', 'UK 10', 'UK 10-12', 'UK 12', 'UK 12-14', 'UK 14', 'UK 14-16', 'UK 16', 'UK 18', 'UK 20', 'XS', 'Size 34', 'Size 36', 'Size 38', 'Size 40', 'Size 42',"s","m","L","xl","2x"); foreach($isize1 as $key => $isize2) { ?><INPUT TYPE="checkbox" NAME="pdzize[]" value="<?=$isize2?>" <?=selected($isize2,$r['pd_size'],0)?>><?=$isize2?>&nbsp;&nbsp;<br/><? } ?>-->
            <label>product description : </label> <br> <?=$rx[lang1]?> <br> <br>
			<textarea name="description" ><?=$r['pd_dese']?></textarea>
			<Br><br> <?=$rx[lang2]?> <br><br> 
			<textarea name="description2" ><?=$r['pd_dese2']?></textarea>

           <br /><br /><br /> <input name="submit" type="submit" value="<?=btsubmit($r['pd_id'])?>" />
            <input name="c_parent" type="hidden" value="<?=$_REQUEST['c_parent']?>" />
            <input name="cmd" type="hidden" value="true" />
            <input name="pd_promo" type="hidden" value="<?=$r['pd_promo']?>" />
            <input name="act" type="hidden" value="<? ($_REQUEST['act'] == "")? print "add":print $_REQUEST['act'];?>" />
            <input name="pd_id" type="hidden" value="<?=$r['pd_id']?>" />
            </form>
            </fieldset>
            
	<br />
<br />
            
            <p>
            <?
            $k=0;
            $r1 = Q2("select * from product p 
			where c_id = '".$_REQUEST['c_parent']."' AND (
			 pd_name like '%".$_REQUEST['txtname']."%' OR
			 pd_name2 like '%".$_REQUEST['txtname']."%' OR
			 pd_code like '%".$_REQUEST['txtname']."%' OR
			 pd_dese like '%".$_REQUEST['txtname']."%' OR
			 pd_dese2 like '%".$_REQUEST['txtname']."%' OR
			 pd_price like '%".$_REQUEST['txtname']."%' OR
			 pd_size like '%".$_REQUEST['txtname']."%' OR
			 pd_size2 like '%".$_REQUEST['txtname']."%' OR
			 pd_unit like '%".$_REQUEST['txtname']."%' OR
			 pd_unit2 like '%".$_REQUEST['txtname']."%' OR
			 pd_promodes like '%".$_REQUEST['txtname']."%' OR
			 pd_promodes2 like '%".$_REQUEST['txtname']."%' OR
			 pd_shotdes like '%".$_REQUEST['txtname']."%' OR
			 pd_shotdes2 like '%".$_REQUEST['txtname']."%' OR
			 pd_color like '%".$_REQUEST['txtname']."%' OR
			 pd_nw like '%".$_REQUEST['txtname']."%' OR
			 pd_nw2 like '%".$_REQUEST['txtname']."%' OR
			 pd_gw like '%".$_REQUEST['txtname']."%' OR
			 pd_gw2 like '%".$_REQUEST['txtname']."%' OR
			 pd_ctnsize like '%".$_REQUEST['txtname']."%' OR
			 pd_ctnsize2 like '%".$_REQUEST['txtname']."%' 
			 )
			 order by pd_order desc");
			/*echo "select * from product p 
			where c_id = '".$_REQUEST['c_parent']."' AND (
			 pd_name like '%".$_REQUEST['txtname']."%' OR
			 pd_name2 like '%".$_REQUEST['txtname']."%' OR
			 pd_code like '%".$_REQUEST['txtname']."%' OR
			 pd_dese like '%".$_REQUEST['txtname']."%' OR
			 pd_dese2 like '%".$_REQUEST['txtname']."%' OR
			 pd_price like '%".$_REQUEST['txtname']."%' OR
			 pd_size like '%".$_REQUEST['txtname']."%' OR
			 pd_size2 like '%".$_REQUEST['txtname']."%' OR
			 pd_unit like '%".$_REQUEST['txtname']."%' OR
			 pd_unit2 like '%".$_REQUEST['txtname']."%' OR
			 pd_promodes like '%".$_REQUEST['txtname']."%' OR
			 pd_promodes2 like '%".$_REQUEST['txtname']."%' OR
			 pd_shotdes like '%".$_REQUEST['txtname']."%' OR
			 pd_shotdes2 like '%".$_REQUEST['txtname']."%' OR
			 pd_color like '%".$_REQUEST['txtname']."%' OR
			 pd_nw like '%".$_REQUEST['txtname']."%' OR
			 pd_nw2 like '%".$_REQUEST['txtname']."%' OR
			 pd_gw like '%".$_REQUEST['txtname']."%' OR
			 pd_gw2 like '%".$_REQUEST['txtname']."%' OR
			 pd_ctnsize like '%".$_REQUEST['txtname']."%' OR
			 pd_ctnsize2 like '%".$_REQUEST['txtname']."%' 
			 )
			 order by pd_order desc";*/
			 $cnt = 0;
            foreach($r1 as $r) {$orderingg[] = $r['pd_id']; $cnt++;}
			
			?>
            <style type="text/css">
				td , th{
					padding: 5px 5px 5px 5px;
				}
			</style>
            <form action = "?body=product" method = "post">
            	ค้นหา : <input type = "text" name = "txtname" value="<?=$_REQUEST['txtname']?>"/>
                <input name="c_parent" type="hidden" value="<?=$_REQUEST['c_parent']?>" />
                <input type = "submit" value="submit"/> <?=" ทั้งหมด <b>".$cnt."</b> รายการ"?>
            </form>
			<table border = 1 style="border:solid 1px #CCC;border-collapse:collapse;width:450px;">
            	<tr>
                	<?
                    	if($_REQUEST['txtname'] == ""){
							echo "<th>จัดลำดับ</th>";
						}
					?>
                    
                    <th>แก้ไขข้อมูล</th>
                    <th>แก้ไขรูปภาพ</th>
                    <th>ลบ</th>
					<th>รูปภาพผลิตภัณฑ์</th>
                    <th>รหัสผลิตภัณฑ์</th>
                    <th>ชื่อผลิตภัณฑ์</th>
                    <th width = 100>ลิ้งค์</th>
                </tr>
			<?
            foreach($r1 as $r)
            {
            ?>
            <div>	
					  
			<?
			
				$rpic1 = Q1("select img_pic,img_name1,img_id from images where na_id='".$r['pd_id']."'  and tables = 'product'  order by img_order desc limit 1 "); 
				
             	if($_SERVER['HTTP_HOST'] == "localhost"){
					$host = 	$_SERVER['HTTP_HOST']."/subkamol";
				}else{
					$host = $_SERVER['HTTP_HOST'];
				}
			 ?>
            </div>
            
            <tr>
            	<?
                    	if($_REQUEST['txtname'] == ""){
							?>
								<td>
                                    [&nbsp;
                                    <? if($orderingg[($k-1)] > 0) { ?>
                                    <a href="?body=product&step=1&c_parent=<?=$_REQUEST['c_parent']?>&page=<?=$_REQUEST['page']?>&swap1=<?=$orderingg[$k]?>&swap2=<?=($orderingg[($k-1)])?>"><img src="images/uparrow.png" width="10" height="10" alt="Move up" title="Move up"  <?=btswap()?> border="0" ></a> 					
                                    <? } ?>
                                    <? if($orderingg[($k+1)] > 0) { ?>
                                    <a href="?body=product&step=1&c_parent=<?=$_REQUEST['c_parent']?>&page=<?=$_REQUEST['page']?>&swap1=<?=$orderingg[$k]?>&swap2=<?=($orderingg[($k+1)])?>"><img src="images/downarrow.png" width="10" height="10" alt="Move down" title="Move down"  <?=btswap()?> border="0" ></a>
                                    <? } ?>&nbsp;]
                                </td>
							<?
						}
				?>
            	
                <td>
                	&nbsp;<a href="?body=product&step=1&c_id=<?=$_REQUEST['c_id']?>&pd_id=<?=$r['pd_id']?>&c_parent=<?=$_REQUEST['c_parent']?>&act=edit"><img src="images/addedit.png" width="15" height="15" alt="Edit" title="Edit"  <?=btswap()?> border="0" ></a>&nbsp;
                </td>
                <td>
                	&nbsp;<a href="?body=addpic2&na_id=<?=$r['pd_id']?>&tables=product"><img src="images/mediamanager.png" width="15" height="15" alt="Edit Images" title="Edit Images"  <?=btswap()?> border="0" ></a>&nbsp;
                </td>
                <td>
                	<a href="?body=product&step=1&c_id=<?=$_REQUEST['c_id']?>&pd_id=<?=$r['pd_id']?>&page=<?=$_REQUEST['page']?>&delid=<?=$r['pd_id']?>&c_parent=<?=$_REQUEST['c_parent']?>" onclick="javascript:if(confirm('Are you sure you want to delete')){return true;} else{return false;};"  > <img src="images/cancel_f2.png" alt="Delete" title="Delete"  width="15" height="15" border="0" <?=btswap()?> ></a>
                </td>
                <td>
                	<?
						if($rpic1['img_pic'] == ""){
							$rpic1['img_pic'] = "no_photo.gif";
						}else{
							
						}
                    ?>
                	<img src = "../imgs/<?=$rpic1['img_pic']?>" style="width:30px;height:30px;" />
                </td>
                <td><?=$r['pd_code']?></td>
                <td><?=$r['pd_name']?> / <?=$r['pd_name2']?></td>
                <td width = 100>
                	<a target = "_new" href = "http://<?=$host."/index.php?pd_id=".$r['pd_id']."&img_id=".$rpic1['img_id']?>" >http://<?=$host."/index.php?pd_id=".$r['pd_id']."&img_id=".$rpic1['img_id']?></a>
                </td>
            </tr>
<?
            $k++;
            }
            ?>
            </table>
            </p>
<?
}
else
{
?>            
			<form action="" method="POST" name="a">
            <fieldset>
            <legend>Step 1 : Choose category</legend>
           
            <select name="c_parent">
            <?
           // $r1 = Q2("select * from category order by c_order desc");
            foreach($chk as $r)
            {
            ?>
            <option value="<?=$r['c_id']?>"><?=$r['c_name']?> / <?=$r['c_name2']?></option>
            <?
            }
            ?>
            </select>
            <br />
            <br />
            <input name="submit" type="submit" value="submit" />
            </fieldset>
            <input name="step" type="hidden" value="1" />
            <input name="body" type="hidden" value="product" />
            
            </form>
            
             <p>
            <?
            $k=0;
			if($_REQUEST['txtname'] != ""){
				$where2 = "where (
			 pd_name like '%".$_REQUEST['txtname']."%' OR
			 pd_name2 like '%".$_REQUEST['txtname']."%' OR
			 pd_code like '%".$_REQUEST['txtname']."%' OR
			 pd_dese like '%".$_REQUEST['txtname']."%' OR
			 pd_dese2 like '%".$_REQUEST['txtname']."%' OR
			 pd_price like '%".$_REQUEST['txtname']."%' OR
			 pd_size like '%".$_REQUEST['txtname']."%' OR
			 pd_size2 like '%".$_REQUEST['txtname']."%' OR
			 pd_unit like '%".$_REQUEST['txtname']."%' OR
			 pd_unit2 like '%".$_REQUEST['txtname']."%' OR
			 pd_promodes like '%".$_REQUEST['txtname']."%' OR
			 pd_promodes2 like '%".$_REQUEST['txtname']."%' OR
			 pd_shotdes like '%".$_REQUEST['txtname']."%' OR
			 pd_shotdes2 like '%".$_REQUEST['txtname']."%' OR
			 pd_color like '%".$_REQUEST['txtname']."%' OR
			 pd_nw like '%".$_REQUEST['txtname']."%' OR
			 pd_nw2 like '%".$_REQUEST['txtname']."%' OR
			 pd_gw like '%".$_REQUEST['txtname']."%' OR
			 pd_gw2 like '%".$_REQUEST['txtname']."%' OR
			 pd_ctnsize like '%".$_REQUEST['txtname']."%' OR 
			 pd_ctnsize2 like '%".$_REQUEST['txtname']."%'  OR 
			 c.c_name like '%".$_REQUEST['txtname']."%'  OR 
			 c.c_name2 like '%".$_REQUEST['txtname']."%'
			 ) ";	
			}
            $r1 = Q2("select * from product p 
			inner join category c on c.c_id = p.c_id 
			".$where2."
			 order by pd_order desc");
			/*echo "select * from product p 
			where (
			 pd_name like '%".$_REQUEST['txtname']."%' OR
			 pd_name2 like '%".$_REQUEST['txtname']."%' OR
			 pd_code like '%".$_REQUEST['txtname']."%' OR
			 pd_dese like '%".$_REQUEST['txtname']."%' OR
			 pd_dese2 like '%".$_REQUEST['txtname']."%' OR
			 pd_price like '%".$_REQUEST['txtname']."%' OR
			 pd_size like '%".$_REQUEST['txtname']."%' OR
			 pd_size2 like '%".$_REQUEST['txtname']."%' OR
			 pd_unit like '%".$_REQUEST['txtname']."%' OR
			 pd_unit2 like '%".$_REQUEST['txtname']."%' OR
			 pd_promodes like '%".$_REQUEST['txtname']."%' OR
			 pd_promodes2 like '%".$_REQUEST['txtname']."%' OR
			 pd_shotdes like '%".$_REQUEST['txtname']."%' OR
			 pd_shotdes2 like '%".$_REQUEST['txtname']."%' OR
			 pd_color like '%".$_REQUEST['txtname']."%' OR
			 pd_nw like '%".$_REQUEST['txtname']."%' OR
			 pd_nw2 like '%".$_REQUEST['txtname']."%' OR
			 pd_gw like '%".$_REQUEST['txtname']."%' OR
			 pd_gw2 like '%".$_REQUEST['txtname']."%' OR
			 pd_ctnsize like '%".$_REQUEST['txtname']."%' OR 
			 pd_ctnsize2 like '%".$_REQUEST['txtname']."%'  OR 
			 c.c_name like '%".$_REQUEST['txtname']."%'  OR 
			 c.c_name2 like '%".$_REQUEST['txtname']."%'
			 ) 
			 order by pd_order desc";*/
			 $cnt = 0;
            foreach($r1 as $r) {$orderingg[] = $r['pd_id']; $cnt++;}
			
			?>
            <style type="text/css">
				td , th{
					padding: 5px 5px 5px 5px;
				}
			</style>
            <form action = "?body=product" method = "post">
            	ค้นหาทุกหมวดหมู่ : <input type = "text" name = "txtname" value="<?=$_REQUEST['txtname']?>"/>
                <input name="c_parent" type="hidden" value="<?=$_REQUEST['c_parent']?>" />
                <input type = "submit" value="submit"/> <?=" ทั้งหมด <b>".$cnt."</b> รายการ"?>
            </form>
			<table border = 1 style="border:solid 1px #CCC;border-collapse:collapse;width:450px;">
            	<tr>
                	
                    <th>แก้ไขข้อมูล</th>
                    <th>แก้ไขรูปภาพ</th>
                    <th>ลบ</th>
					<th>รูปภาพผลิตภัณฑ์</th>
                    <th>หมวดหมู่ผลิตภัณฑ์</th>
                    <th>รหัสผลิตภัณฑ์</th>
                    <th>ชื่อผลิตภัณฑ์</th>
                    <th width = 100>ลิ้งค์</th>
                </tr>
			<?
            foreach($r1 as $r)
            {
            ?>
            <div>	
					  
			<?
			
				$rpic1 = Q1("select img_pic,img_name1,img_id from images where na_id='".$r['pd_id']."'  and tables = 'product'  order by img_order desc limit 1 "); 
				
             	if($_SERVER['HTTP_HOST'] == "localhost"){
					$host = 	$_SERVER['HTTP_HOST']."/subkamol";
				}else{
					$host = $_SERVER['HTTP_HOST'];
				}
			 ?>
            </div>
            
            <tr>
            	
            	
                <td>
                	&nbsp;<a rel = "prettyPhoto" href="all_edit.php?body=product&step=1&c_id=<?=$_REQUEST['c_id']?>&pd_id=<?=$r['pd_id']?>&c_parent=<?=$_REQUEST['c_parent']?>&act=edit&iframe=true&width=1000&height=500"><img src="images/addedit.png" width="15" height="15" alt="Edit" title="Edit"  <?=btswap()?> border="0" ></a>&nbsp;
                </td>
                <td>
                	&nbsp;<a href="?body=addpic2&na_id=<?=$r['pd_id']?>&tables=product"><img src="images/mediamanager.png" width="15" height="15" alt="Edit Images" title="Edit Images"  <?=btswap()?> border="0" ></a>&nbsp;
                </td>
                <td>
                	<a href="?body=product&step=1&c_id=<?=$_REQUEST['c_id']?>&pd_id=<?=$r['pd_id']?>&page=<?=$_REQUEST['page']?>&delid=<?=$r['pd_id']?>&c_parent=<?=$_REQUEST['c_parent']?>" onclick="javascript:if(confirm('Are you sure you want to delete')){return true;} else{return false;};"  > <img src="images/cancel_f2.png" alt="Delete" title="Delete"  width="15" height="15" border="0" <?=btswap()?> ></a>
                </td>
                <td>
                	<?
						if($rpic1['img_pic'] == ""){
							$rpic1['img_pic'] = "no_photo.gif";
						}else{
							
						}
                    ?>
                	<img src = "../imgs/<?=$rpic1['img_pic']?>" style="width:30px;height:30px;" />
                </td>
                <td><?=$r['c_name']." / ".$r['c_name2']?></td>
                <td><?=$r['pd_code']?></td>
                <td><?=$r['pd_name']?> / <?=$r['pd_name2']?></td>
                <td width = 100>
                	<a target = "_new" href = "http://<?=$host."/index.php?pd_id=".$r['pd_id']."&img_id=".$rpic1['img_id']?>" >http://<?=$host."/index.php?pd_id=".$r['pd_id']."&img_id=".$rpic1['img_id']?></a>
                </td>
            </tr>
<?
            $k++;
            }
            ?>
            </table>
            </p>
<?
}
?>

<script>

var path = "admin/js";	
CKEDITOR.replace( 'description' ,{
	filebrowserBrowseUrl : path+'/ckfinder/ckfinder.html',
    filebrowserImageBrowseUrl : path+'/ckfinder/ckfinder.html?Type=Images',
    filebrowserFlashBrowseUrl : path+'/ckfinder/ckfinder.html?Type=Flash',
    filebrowserUploadUrl : path+'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
    filebrowserImageUploadUrl :path+ '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
    filebrowserFlashUploadUrl : path+'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
	width:500,
	height:200
	
	});
	CKEDITOR.replace( 'description2' ,{
	filebrowserBrowseUrl : path+'/ckfinder/ckfinder.html',
    filebrowserImageBrowseUrl : path+'/ckfinder/ckfinder.html?Type=Images',
    filebrowserFlashBrowseUrl :path+ '/ckfinder/ckfinder.html?Type=Flash',
    filebrowserUploadUrl : path+'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
    filebrowserImageUploadUrl :path+ '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
    filebrowserFlashUploadUrl :path+'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
	width:500,
	height:200
	});
	
	$('input[name=pd_promo1]').live('click',function(){
			$('#promo_panel').toggle('fast');
			
			
			if($('input[name=pd_promo1]').attr('checked') == "checked"){
			//alert('check'+$('#all_checked').attr('checked'));
			$('input[name=pd_promo]').val(1);
		}else{
			//alert('uncheck'+$('#all_checked').attr('checked'));	
			$('input[name=pd_promo]').val(0);
		}
	});
	$('input[name=pd_publish]').live('click',function(){
			if($('input[name=pd_publish]').attr('checked') == "checked"){
			//alert('check'+$('#all_checked').attr('checked'));
			$('input[name=pd_publish]').val(1);
		}else{
			//alert('uncheck'+$('#all_checked').attr('checked'));	
			$('input[name=pd_publish]').val(0);
		}
	});
	
	
</script>
